<?php
/**
 * DouPHP小程序模块
 * Author: cuihaifeng  qq 366131726 微信同号
 * 网址：www.zbxingke.com www.0533hf.com
 */

define('IN_DOUCO_API', true);
require (dirname(__FILE__) . '/include/init.php');

load()->func('app');


$acl = array(
    'home' => array(
        'default' => 'home',
    )
);


$controllers = array();
$handle = opendir(LOADER_PATH. 'source/');
if(!empty($handle)) {
    while($dir = readdir($handle)) {
        if($dir != '.' && $dir != '..') {
            $controllers[] = $dir;
        }
    }
}

if(!in_array($controller, $controllers)) {
    $controller = 'home';
}
$init = LOADER_PATH . "source/{$controller}/__init.php";
if(is_file($init)) {
    require $init;
}
$actions = array();
$handle = opendir(LOADER_PATH . 'source/' . $controller);
if(!empty($handle)) {
    while($dir = readdir($handle)) {
        if($dir != '.' && $dir != '..' && strexists($dir, '.ctrl.php')) {
            $dir = str_replace('.ctrl.php', '', $dir);
            $actions[] = $dir;
        }
    }
}

if(!in_array($action, $actions)) {
    $action = $acl[$controller]['default'];
}
if(!in_array($action, $actions)) {
    $action = $actions[0];
}
require _forward($controller, $action);

//执行方法
$method = 'doPage' . ucfirst($do);

$method();

exit();

/**
 * 执行控制器文件
 * @param $c
 * @param $a
 * @return string
 */
function _forward($c, $a) {
    $file = LOADER_PATH . 'source/' . $c . '/' . $a . '.ctrl.php';
    return $file;
}

